<!DOCTYPE html>
<html lang="si">
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta name="description" content="මෙය වර්ගීකරණ කාර්යයන් සඳහා නැවත භාවිතා කළ හැකි පුහුණුකරුවකි"/>

    <meta name="twitter:card" content="summary"/>
    <meta name="twitter:image:src" content="https://avatars1.githubusercontent.com/u/64068543?s=400&amp;v=4"/>
    <meta name="twitter:title" content="NLP වර්ගීකරණ පුහුණුකරු"/>
    <meta name="twitter:description" content="මෙය වර්ගීකරණ කාර්යයන් සඳහා නැවත භාවිතා කළ හැකි පුහුණුකරුවකි"/>
    <meta name="twitter:site" content="@labmlai"/>
    <meta name="twitter:creator" content="@labmlai"/>

    <meta property="og:url" content="https://nn.labml.ai/experiments/nlp_classification.html"/>
    <meta property="og:title" content="NLP වර්ගීකරණ පුහුණුකරු"/>
    <meta property="og:image" content="https://avatars1.githubusercontent.com/u/64068543?s=400&amp;v=4"/>
    <meta property="og:site_name" content="NLP වර්ගීකරණ පුහුණුකරු"/>
    <meta property="og:type" content="object"/>
    <meta property="og:title" content="NLP වර්ගීකරණ පුහුණුකරු"/>
    <meta property="og:description" content="මෙය වර්ගීකරණ කාර්යයන් සඳහා නැවත භාවිතා කළ හැකි පුහුණුකරුවකි"/>

    <title>NLP වර්ගීකරණ පුහුණුකරු</title>
    <link rel="shortcut icon" href="/icon.png"/>
    <link rel="stylesheet" href="../pylit.css?v=1">
    <link rel="canonical" href="https://nn.labml.ai/experiments/nlp_classification.html"/>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.13.18/dist/katex.min.css" integrity="sha384-zTROYFVGOfTw7JV7KUu8udsvW2fx4lWOsCEDqhBreBwlHI4ioVRtmIvEThzJHGET" crossorigin="anonymous">

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-4V3HC8HBLH"></script>
    <script>
        window.dataLayer = window.dataLayer || [];

        function gtag() {
            dataLayer.push(arguments);
        }

        gtag('js', new Date());

        gtag('config', 'G-4V3HC8HBLH');
    </script>
</head>
<body>
<div id='container'>
    <div id="background"></div>
    <div class='section'>
        <div class='docs'>
            <p>
                <a class="parent" href="/">home</a>
                <a class="parent" href="index.html">experiments</a>
            </p>
            <p>
                <a href="https://github.com/labmlai/annotated_deep_learning_paper_implementations" target="_blank">
                    <img alt="Github"
                         src="https://img.shields.io/github/stars/labmlai/annotated_deep_learning_paper_implementations?style=social"
                         style="max-width:100%;"/></a>
                <a href="https://twitter.com/labmlai" rel="nofollow" target="_blank">
                    <img alt="Twitter"
                         src="https://img.shields.io/twitter/follow/labmlai?style=social"
                         style="max-width:100%;"/></a>
            </p>
            <p>
                <a href="https://github.com/labmlai/annotated_deep_learning_paper_implementations/tree/master/labml_nn/experiments/nlp_classification.py" target="_blank">
                    View code on Github</a>
            </p>
        </div>
    </div>
    <div class='section' id='section-0'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-0'>#</a>
            </div>
            <h1>වර්ගීකරණයසඳහා NLP ආකෘති පුහුණුකරු</h1>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">11</span><span></span><span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">Counter</span>
<span class="lineno">12</span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Callable</span>
<span class="lineno">13</span>
<span class="lineno">14</span><span class="kn">import</span> <span class="nn">torch</span>
<span class="lineno">15</span><span class="kn">import</span> <span class="nn">torchtext</span>
<span class="lineno">16</span><span class="kn">from</span> <span class="nn">torch</span> <span class="kn">import</span> <span class="n">nn</span>
<span class="lineno">17</span><span class="kn">from</span> <span class="nn">torch.utils.data</span> <span class="kn">import</span> <span class="n">DataLoader</span>
<span class="lineno">18</span><span class="kn">import</span> <span class="nn">torchtext.vocab</span>
<span class="lineno">19</span><span class="kn">from</span> <span class="nn">torchtext.vocab</span> <span class="kn">import</span> <span class="n">Vocab</span>
<span class="lineno">20</span>
<span class="lineno">21</span><span class="kn">from</span> <span class="nn">labml</span> <span class="kn">import</span> <span class="n">lab</span><span class="p">,</span> <span class="n">tracker</span><span class="p">,</span> <span class="n">monit</span>
<span class="lineno">22</span><span class="kn">from</span> <span class="nn">labml.configs</span> <span class="kn">import</span> <span class="n">option</span>
<span class="lineno">23</span><span class="kn">from</span> <span class="nn">labml_helpers.device</span> <span class="kn">import</span> <span class="n">DeviceConfigs</span>
<span class="lineno">24</span><span class="kn">from</span> <span class="nn">labml_helpers.metrics.accuracy</span> <span class="kn">import</span> <span class="n">Accuracy</span>
<span class="lineno">25</span><span class="kn">from</span> <span class="nn">labml_helpers.module</span> <span class="kn">import</span> <span class="n">Module</span>
<span class="lineno">26</span><span class="kn">from</span> <span class="nn">labml_helpers.train_valid</span> <span class="kn">import</span> <span class="n">TrainValidConfigs</span><span class="p">,</span> <span class="n">hook_model_outputs</span><span class="p">,</span> <span class="n">BatchIndex</span>
<span class="lineno">27</span><span class="kn">from</span> <span class="nn">labml_nn.optimizers.configs</span> <span class="kn">import</span> <span class="n">OptimizerConfigs</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-1'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-1'>#</a>
            </div>
            <p> <a id="NLPClassificationConfigs"></a></p>
<h2>පුහුණුකරුමානකරණ</h2>
<p>එන්එල්පීවර්ගීකරණ කාර්ය පුහුණුව සඳහා මූලික වින්යාසයන් මෙයට ඇත. සියලුම ගුණාංග වින්යාසගත කළ හැකිය. </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">30</span><span class="k">class</span> <span class="nc">NLPClassificationConfigs</span><span class="p">(</span><span class="n">TrainValidConfigs</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-2'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-2'>#</a>
            </div>
            <p>ප්රශස්තකරණය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">41</span>    <span class="n">optimizer</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">optim</span><span class="o">.</span><span class="n">Adam</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-3'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-3'>#</a>
            </div>
            <p>පුහුණුඋපාංගය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">43</span>    <span class="n">device</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">device</span> <span class="o">=</span> <span class="n">DeviceConfigs</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-4'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-4'>#</a>
            </div>
            <p>ස්වයංක්රීයප්රතිගාමී ආකෘතිය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">46</span>    <span class="n">model</span><span class="p">:</span> <span class="n">Module</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-5'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-5'>#</a>
            </div>
            <p>කණ්ඩායම්ප්රමාණය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">48</span>    <span class="n">batch_size</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">16</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-6'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-6'>#</a>
            </div>
            <p>අනුක්රමයේදිග, හෝ සන්දර්භය ප්රමාණය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">50</span>    <span class="n">seq_len</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">512</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-7'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-7'>#</a>
            </div>
            <p>වචනමාලාව </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">52</span>    <span class="n">vocab</span><span class="p">:</span> <span class="n">Vocab</span> <span class="o">=</span> <span class="s1">&#39;ag_news&#39;</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-8'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-8'>#</a>
            </div>
            <p>වචනමාලාවේ ටෝකන් ගණන </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">54</span>    <span class="n">n_tokens</span><span class="p">:</span> <span class="nb">int</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-9'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-9'>#</a>
            </div>
            <p>පන්තිගණන </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">56</span>    <span class="n">n_classes</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="s1">&#39;ag_news&#39;</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-10'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-10'>#</a>
            </div>
            <p>ටෝකනයිසර් </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">58</span>    <span class="n">tokenizer</span><span class="p">:</span> <span class="n">Callable</span> <span class="o">=</span> <span class="s1">&#39;character&#39;</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-11'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-11'>#</a>
            </div>
            <p>වරින්වර ආකෘති සුරැකීමට යන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">61</span>    <span class="n">is_save_models</span> <span class="o">=</span> <span class="kc">True</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-12'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-12'>#</a>
            </div>
            <p>පාඩුශ්රිතය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">64</span>    <span class="n">loss_func</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">CrossEntropyLoss</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-13'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-13'>#</a>
            </div>
            <p>නිරවද්යතාශ්රිතය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">66</span>    <span class="n">accuracy</span> <span class="o">=</span> <span class="n">Accuracy</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-14'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-14'>#</a>
            </div>
            <p>ආදර්ශකාවැද්දීමේ ප්රමාණය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">68</span>    <span class="n">d_model</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">512</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-15'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-15'>#</a>
            </div>
            <p>ශ්රේණියේක්ලිපින් </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">70</span>    <span class="n">grad_norm_clip</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">1.0</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-16'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-16'>#</a>
            </div>
            <p>පුහුණුදත්ත පැටවුම </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">73</span>    <span class="n">train_loader</span><span class="p">:</span> <span class="n">DataLoader</span> <span class="o">=</span> <span class="s1">&#39;ag_news&#39;</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-17'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-17'>#</a>
            </div>
            <p>වලංගුදත්ත පැටවුම </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">75</span>    <span class="n">valid_loader</span><span class="p">:</span> <span class="n">DataLoader</span> <span class="o">=</span> <span class="s1">&#39;ag_news&#39;</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-18'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-18'>#</a>
            </div>
            <p>ආදර්ශපරාමිතීන් සහ අනුක්රමික ලඝු-සටහන යන්න (එක් එක් එක් එක් එක් වරක්). මේවා ස්ථරයකට සාරාංශගත සංඛ්යාන වේ, නමුත් එය තවමත් ඉතා ගැඹුරු ජාල සඳහා බොහෝ දර්ශක වලට හේතු විය හැකිය. </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">80</span>    <span class="n">is_log_model_params_grads</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-19'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-19'>#</a>
            </div>
            <p>ආදර්ශසක්රිය කිරීම් ලොග් කළ යුතුද යන්න (එක් එක් ඊපෝච් එකකට වරක්). මේවා ස්ථරයකට සාරාංශගත සංඛ්යාන වේ, නමුත් එය තවමත් ඉතා ගැඹුරු ජාල සඳහා බොහෝ දර්ශක වලට හේතු විය හැකිය. </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">85</span>    <span class="n">is_log_model_activations</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-20'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-20'>#</a>
            </div>
            <h3>ආරම්භකකරණය</h3>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">87</span>    <span class="k">def</span> <span class="nf">init</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-21'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-21'>#</a>
            </div>
            <p>ට්රැකර්වින්යාසයන් සකසන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">92</span>        <span class="n">tracker</span><span class="o">.</span><span class="n">set_scalar</span><span class="p">(</span><span class="s2">&quot;accuracy.*&quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<span class="lineno">93</span>        <span class="n">tracker</span><span class="o">.</span><span class="n">set_scalar</span><span class="p">(</span><span class="s2">&quot;loss.*&quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-22'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-22'>#</a>
            </div>
            <p>මොඩියුලප්රතිදානයන් ලොග් කිරීමට කොක්කක් එක් කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">95</span>        <span class="n">hook_model_outputs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mode</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">,</span> <span class="s1">&#39;model&#39;</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-23'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-23'>#</a>
            </div>
            <p>රාජ්යමොඩියුලයක් ලෙස නිරවද්යතාව එක් කරන්න. RNs සඳහා පුහුණුව සහ වලංගු කිරීම අතර රාජ්යයන් ගබඩා කිරීම අදහස් කරන බැවින් නම බොහෝ විට ව්යාකූල වේ. මෙය පුහුණුව සහ වලංගු කිරීම සඳහා නිරවද්යතා මෙට්රික් සංඛ්යාන වෙනම තබා ගනී. </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">100</span>        <span class="bp">self</span><span class="o">.</span><span class="n">state_modules</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">accuracy</span><span class="p">]</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-24'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-24'>#</a>
            </div>
            <h3>පුහුණුවහෝ වලංගු කිරීමේ පියවර</h3>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">102</span>    <span class="k">def</span> <span class="nf">step</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">batch</span><span class="p">:</span> <span class="nb">any</span><span class="p">,</span> <span class="n">batch_idx</span><span class="p">:</span> <span class="n">BatchIndex</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-25'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-25'>#</a>
            </div>
            <p>උපාංගයවෙත දත්ත ගෙනයන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">108</span>        <span class="n">data</span><span class="p">,</span> <span class="n">target</span> <span class="o">=</span> <span class="n">batch</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">),</span> <span class="n">batch</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-26'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-26'>#</a>
            </div>
            <p>පුහුණුප්රකාරයේදී ගෝලීය පියවර යාවත්කාලීන කරන්න (සැකසූ ටෝකන ගණන) </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">111</span>        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">mode</span><span class="o">.</span><span class="n">is_train</span><span class="p">:</span>
<span class="lineno">112</span>            <span class="n">tracker</span><span class="o">.</span><span class="n">add_global_step</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-27'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-27'>#</a>
            </div>
            <p>ආකෘතිප්රතිදානයන් ග්රහණය කර ගත යුතුද යන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">115</span>        <span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">mode</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">is_log_activations</span><span class="o">=</span><span class="n">batch_idx</span><span class="o">.</span><span class="n">is_last</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_log_model_activations</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-28'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-28'>#</a>
            </div>
            <p>ආදර්ශප්රතිදානයන් ලබා ගන්න. ආර්එන්එස් භාවිතා කරන විට එය ප්රාන්ත සඳහා ටූල් එකක් නැවත ලබා දෙයි. මෙය තවම ක්රියාත්මක කර නැත 😜 </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">119</span>            <span class="n">output</span><span class="p">,</span> <span class="o">*</span><span class="n">_</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">(</span><span class="n">data</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-29'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-29'>#</a>
            </div>
            <p>ගණනයකිරීම සහ ලොග් වීම </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">122</span>        <span class="n">loss</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">loss_func</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">target</span><span class="p">)</span>
<span class="lineno">123</span>        <span class="n">tracker</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s2">&quot;loss.&quot;</span><span class="p">,</span> <span class="n">loss</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-30'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-30'>#</a>
            </div>
            <p>ගණනයකිරීම සහ ලොග් කිරීමේ නිරවද්යතාවය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">126</span>        <span class="bp">self</span><span class="o">.</span><span class="n">accuracy</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">target</span><span class="p">)</span>
<span class="lineno">127</span>        <span class="bp">self</span><span class="o">.</span><span class="n">accuracy</span><span class="o">.</span><span class="n">track</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-31'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-31'>#</a>
            </div>
            <p>ආකෘතියපුහුණු කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">130</span>        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">mode</span><span class="o">.</span><span class="n">is_train</span><span class="p">:</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-32'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-32'>#</a>
            </div>
            <p>අනුක්රමිකගණනය කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">132</span>            <span class="n">loss</span><span class="o">.</span><span class="n">backward</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-33'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-33'>#</a>
            </div>
            <p>ක්ලිප්අනුක්රමික </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">134</span>            <span class="n">torch</span><span class="o">.</span><span class="n">nn</span><span class="o">.</span><span class="n">utils</span><span class="o">.</span><span class="n">clip_grad_norm_</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">parameters</span><span class="p">(),</span> <span class="n">max_norm</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">grad_norm_clip</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-34'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-34'>#</a>
            </div>
            <p>ප්රශස්තිකරණපියවර ගන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">136</span>            <span class="bp">self</span><span class="o">.</span><span class="n">optimizer</span><span class="o">.</span><span class="n">step</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-35'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-35'>#</a>
            </div>
            <p>සෑමයුගලයකම අවසාන කණ්ඩායමේ ආදර්ශ පරාමිතීන් සහ අනුක්රමික ලොග් කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">138</span>            <span class="k">if</span> <span class="n">batch_idx</span><span class="o">.</span><span class="n">is_last</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_log_model_params_grads</span><span class="p">:</span>
<span class="lineno">139</span>                <span class="n">tracker</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;model&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-36'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-36'>#</a>
            </div>
            <p>අනුක්රමිකඉවත් </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">141</span>            <span class="bp">self</span><span class="o">.</span><span class="n">optimizer</span><span class="o">.</span><span class="n">zero_grad</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-37'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-37'>#</a>
            </div>
            <p>ලුහුබැඳඇති ප්රමිතික සුරකින්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">144</span>        <span class="n">tracker</span><span class="o">.</span><span class="n">save</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-38'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-38'>#</a>
            </div>
            <h3>පෙරනිමි <a href="../optimizers/configs.html">ප්රශස්තිකරණ වින්යාසයන්</a></h3>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">147</span><span class="nd">@option</span><span class="p">(</span><span class="n">NLPClassificationConfigs</span><span class="o">.</span><span class="n">optimizer</span><span class="p">)</span>
<span class="lineno">148</span><span class="k">def</span> <span class="nf">_optimizer</span><span class="p">(</span><span class="n">c</span><span class="p">:</span> <span class="n">NLPClassificationConfigs</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-39'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-39'>#</a>
            </div>
            
        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">153</span>    <span class="n">optimizer</span> <span class="o">=</span> <span class="n">OptimizerConfigs</span><span class="p">()</span>
<span class="lineno">154</span>    <span class="n">optimizer</span><span class="o">.</span><span class="n">parameters</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">parameters</span><span class="p">()</span>
<span class="lineno">155</span>    <span class="n">optimizer</span><span class="o">.</span><span class="n">optimizer</span> <span class="o">=</span> <span class="s1">&#39;Adam&#39;</span>
<span class="lineno">156</span>    <span class="n">optimizer</span><span class="o">.</span><span class="n">d_model</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">d_model</span>
<span class="lineno">157</span>
<span class="lineno">158</span>    <span class="k">return</span> <span class="n">optimizer</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-40'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-40'>#</a>
            </div>
            <h3>මූලිකඉංග්රීසි ටෝකනයිසර්</h3>
<p>මෙමඅත්හදා බැලීමේදී අපි චරිත මට්ටමේ ටෝකනයිසර් භාවිතා කරමු. සැකසීමෙන් ඔබට මාරු විය හැකිය,</p>
<pre  class="highlight lang-"><code><span></span><span class="s1">&#39;tokenizer&#39;</span><span class="p">:</span> <span class="s1">&#39;basic_english&#39;</span><span class="p">,</span></code></pre>
<p>අත්හදාබැලීම ආරම්භ කිරීමේදී වින්යාස කිරීමේ ශබ්දකෝෂයේ. </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">161</span><span class="nd">@option</span><span class="p">(</span><span class="n">NLPClassificationConfigs</span><span class="o">.</span><span class="n">tokenizer</span><span class="p">)</span>
<span class="lineno">162</span><span class="k">def</span> <span class="nf">basic_english</span><span class="p">():</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-41'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-41'>#</a>
            </div>
            
        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">176</span>    <span class="kn">from</span> <span class="nn">torchtext.data</span> <span class="kn">import</span> <span class="n">get_tokenizer</span>
<span class="lineno">177</span>    <span class="k">return</span> <span class="n">get_tokenizer</span><span class="p">(</span><span class="s1">&#39;basic_english&#39;</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-42'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-42'>#</a>
            </div>
            <h3>අක්ෂරමට්ටමේ ටෝකනයිසර්</h3>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">180</span><span class="k">def</span> <span class="nf">character_tokenizer</span><span class="p">(</span><span class="n">x</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-43'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-43'>#</a>
            </div>
            
        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">184</span>    <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="n">x</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-44'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-44'>#</a>
            </div>
            <p> අක්ෂරමට්ටමේ ටෝකනයිසර් වින්යාසය</p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">187</span><span class="nd">@option</span><span class="p">(</span><span class="n">NLPClassificationConfigs</span><span class="o">.</span><span class="n">tokenizer</span><span class="p">)</span>
<span class="lineno">188</span><span class="k">def</span> <span class="nf">character</span><span class="p">():</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-45'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-45'>#</a>
            </div>
            
        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">192</span>    <span class="k">return</span> <span class="n">character_tokenizer</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-46'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-46'>#</a>
            </div>
            <p> ටෝකනගණන ලබා ගන්න</p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">195</span><span class="nd">@option</span><span class="p">(</span><span class="n">NLPClassificationConfigs</span><span class="o">.</span><span class="n">n_tokens</span><span class="p">)</span>
<span class="lineno">196</span><span class="k">def</span> <span class="nf">_n_tokens</span><span class="p">(</span><span class="n">c</span><span class="p">:</span> <span class="n">NLPClassificationConfigs</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-47'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-47'>#</a>
            </div>
            
        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">200</span>    <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">vocab</span><span class="p">)</span> <span class="o">+</span> <span class="mi">2</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-48'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-48'>#</a>
            </div>
            <h2>දත්තකාණ්ඩවලට පැටවීමේ කාර්යය</h2>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">203</span><span class="k">class</span> <span class="nc">CollateFunc</span><span class="p">:</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-49'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-49'>#</a>
            </div>
            <ul><li><code  class="highlight"><span></span><span class="n">tokenizer</span></code>
 ටෝකනයිසර් ශ්රිතය වේ </li>
<li><code  class="highlight"><span></span><span class="n">vocab</span></code>
 යනු වචන මාලාවයි </li>
<li><code  class="highlight"><span></span><span class="n">seq_len</span></code>
 අනුක්රමයේ දිග වේ </li>
<li><code  class="highlight"><span></span><span class="n">padding_token</span></code>
 යනු පෙළ දිගට වඩා විශාල <code  class="highlight"><span></span><span class="n">seq_len</span></code>
 වන විට පෑඩින් කිරීම සඳහා භාවිතා කරන ටෝකනය වේ </li>
<li><code  class="highlight"><span></span><span class="n">classifier_token</span></code>
 යනු ආදානය අවසානයේ අප විසින් සකස් කරන ලද <code  class="highlight"><span></span><span class="p">[</span><span class="n">CLS</span><span class="p">]</span></code>
 ටෝකනයයි</li></ul>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">208</span>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tokenizer</span><span class="p">,</span> <span class="n">vocab</span><span class="p">:</span> <span class="n">Vocab</span><span class="p">,</span> <span class="n">seq_len</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">padding_token</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">classifier_token</span><span class="p">:</span> <span class="nb">int</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-50'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-50'>#</a>
            </div>
            
        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">216</span>        <span class="bp">self</span><span class="o">.</span><span class="n">classifier_token</span> <span class="o">=</span> <span class="n">classifier_token</span>
<span class="lineno">217</span>        <span class="bp">self</span><span class="o">.</span><span class="n">padding_token</span> <span class="o">=</span> <span class="n">padding_token</span>
<span class="lineno">218</span>        <span class="bp">self</span><span class="o">.</span><span class="n">seq_len</span> <span class="o">=</span> <span class="n">seq_len</span>
<span class="lineno">219</span>        <span class="bp">self</span><span class="o">.</span><span class="n">vocab</span> <span class="o">=</span> <span class="n">vocab</span>
<span class="lineno">220</span>        <span class="bp">self</span><span class="o">.</span><span class="n">tokenizer</span> <span class="o">=</span> <span class="n">tokenizer</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-51'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-51'>#</a>
            </div>
            <ul><li><code  class="highlight"><span></span><span class="n">batch</span></code>
 විසින් එකතු කරන ලද දත්ත කාණ්ඩයයි <code  class="highlight"><span></span><span class="n">DataLoader</span></code>
</li></ul>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">222</span>    <span class="k">def</span> <span class="fm">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">batch</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-52'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-52'>#</a>
            </div>
            <p>ආදානදත්ත ටෙන්සරය, සමඟ ආරම්භ කර ඇත <code  class="highlight"><span></span><span class="n">padding_token</span></code>
 </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">228</span>        <span class="n">data</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">full</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">seq_len</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">batch</span><span class="p">)),</span> <span class="bp">self</span><span class="o">.</span><span class="n">padding_token</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">torch</span><span class="o">.</span><span class="n">long</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-53'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-53'>#</a>
            </div>
            <p>හිස්ලේබල් ටෙන්සර් </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">230</span>        <span class="n">labels</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">batch</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">torch</span><span class="o">.</span><span class="n">long</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-54'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-54'>#</a>
            </div>
            <p>සාම්පලහරහා ලූප </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">233</span>        <span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">_label</span><span class="p">,</span> <span class="n">_text</span><span class="p">))</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">batch</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-55'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-55'>#</a>
            </div>
            <p>ලේබලයසකසන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">235</span>            <span class="n">labels</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">_label</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-56'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-56'>#</a>
            </div>
            <p>ආදානපෙළ ටෝකනයිස් කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">237</span>            <span class="n">_text</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">vocab</span><span class="p">[</span><span class="n">token</span><span class="p">]</span> <span class="k">for</span> <span class="n">token</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenizer</span><span class="p">(</span><span class="n">_text</span><span class="p">)]</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-57'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-57'>#</a>
            </div>
            <p>දක්වාටන්ක කරන්න <code  class="highlight"><span></span><span class="n">seq_len</span></code>
 </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">239</span>            <span class="n">_text</span> <span class="o">=</span> <span class="n">_text</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">seq_len</span><span class="p">]</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-58'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-58'>#</a>
            </div>
            <p>දත්තසම්ප්රේෂණය කර එකතු කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">241</span>            <span class="n">data</span><span class="p">[:</span><span class="nb">len</span><span class="p">(</span><span class="n">_text</span><span class="p">),</span> <span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">new_tensor</span><span class="p">(</span><span class="n">_text</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-59'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-59'>#</a>
            </div>
            <p>අනුපිළිවෙලෙහිඅවසාන ටෝකනය සකසන්න <code  class="highlight"><span></span><span class="p">[</span><span class="n">CLS</span><span class="p">]</span></code>
 </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">244</span>        <span class="n">data</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">classifier_token</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-60'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-60'>#</a>
            </div>
            <p> </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">247</span>        <span class="k">return</span> <span class="n">data</span><span class="p">,</span> <span class="n">labels</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-61'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-61'>#</a>
            </div>
            <h3>AGපුවත් දත්ත කට්ටලය</h3>
<p>මෙයAG පුවත් දත්ත සමුදාය පටවන අතර <code  class="highlight"><span></span><span class="n">n_classes</span></code>
, සඳහා අගයන් සකසා ඇත, <code  class="highlight"><span></span><span class="n">vocab</span></code>
, <code  class="highlight"><span></span><span class="n">train_loader</span></code>
, සහ <code  class="highlight"><span></span><span class="n">valid_loader</span></code>
. </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">250</span><span class="nd">@option</span><span class="p">([</span><span class="n">NLPClassificationConfigs</span><span class="o">.</span><span class="n">n_classes</span><span class="p">,</span>
<span class="lineno">251</span>         <span class="n">NLPClassificationConfigs</span><span class="o">.</span><span class="n">vocab</span><span class="p">,</span>
<span class="lineno">252</span>         <span class="n">NLPClassificationConfigs</span><span class="o">.</span><span class="n">train_loader</span><span class="p">,</span>
<span class="lineno">253</span>         <span class="n">NLPClassificationConfigs</span><span class="o">.</span><span class="n">valid_loader</span><span class="p">])</span>
<span class="lineno">254</span><span class="k">def</span> <span class="nf">ag_news</span><span class="p">(</span><span class="n">c</span><span class="p">:</span> <span class="n">NLPClassificationConfigs</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-62'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-62'>#</a>
            </div>
            <p>පුහුණුවසහ වලංගු කිරීමේ දත්ත කට්ටල ලබා ගන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">263</span>    <span class="n">train</span><span class="p">,</span> <span class="n">valid</span> <span class="o">=</span> <span class="n">torchtext</span><span class="o">.</span><span class="n">datasets</span><span class="o">.</span><span class="n">AG_NEWS</span><span class="p">(</span><span class="n">root</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">lab</span><span class="o">.</span><span class="n">get_data_path</span><span class="p">()</span> <span class="o">/</span> <span class="s1">&#39;ag_news&#39;</span><span class="p">),</span> <span class="n">split</span><span class="o">=</span><span class="p">(</span><span class="s1">&#39;train&#39;</span><span class="p">,</span> <span class="s1">&#39;test&#39;</span><span class="p">))</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-63'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-63'>#</a>
            </div>
            <p>මතකයවෙත දත්ත පූරණය කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">266</span>    <span class="k">with</span> <span class="n">monit</span><span class="o">.</span><span class="n">section</span><span class="p">(</span><span class="s1">&#39;Load data&#39;</span><span class="p">):</span>
<span class="lineno">267</span>        <span class="kn">from</span> <span class="nn">labml_nn.utils</span> <span class="kn">import</span> <span class="n">MapStyleDataset</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-64'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-64'>#</a>
            </div>
            <p><a href="../utils.html#map_style_dataset">සිතියම් ආකාරයේ දත්ත කට්ටල</a> සාදන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">270</span>        <span class="n">train</span><span class="p">,</span> <span class="n">valid</span> <span class="o">=</span> <span class="n">MapStyleDataset</span><span class="p">(</span><span class="n">train</span><span class="p">),</span> <span class="n">MapStyleDataset</span><span class="p">(</span><span class="n">valid</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-65'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-65'>#</a>
            </div>
            <p>ටෝකනයිසර්ලබා ගන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">273</span>    <span class="n">tokenizer</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">tokenizer</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-66'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-66'>#</a>
            </div>
            <p>කවුන්ටරයක්සාදන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">276</span>    <span class="n">counter</span> <span class="o">=</span> <span class="n">Counter</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-67'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-67'>#</a>
            </div>
            <p>පුහුණුදත්ත කට්ටලයෙන් ටෝකන එකතු කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">278</span>    <span class="k">for</span> <span class="p">(</span><span class="n">label</span><span class="p">,</span> <span class="n">line</span><span class="p">)</span> <span class="ow">in</span> <span class="n">train</span><span class="p">:</span>
<span class="lineno">279</span>        <span class="n">counter</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">tokenizer</span><span class="p">(</span><span class="n">line</span><span class="p">))</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-68'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-68'>#</a>
            </div>
            <p>වලංගුදත්ත කට්ටලයෙන් ටෝකන එකතු කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">281</span>    <span class="k">for</span> <span class="p">(</span><span class="n">label</span><span class="p">,</span> <span class="n">line</span><span class="p">)</span> <span class="ow">in</span> <span class="n">valid</span><span class="p">:</span>
<span class="lineno">282</span>        <span class="n">counter</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">tokenizer</span><span class="p">(</span><span class="n">line</span><span class="p">))</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-69'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-69'>#</a>
            </div>
            <p>වචනමාලාව සාදන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">284</span>    <span class="n">vocab</span> <span class="o">=</span> <span class="n">torchtext</span><span class="o">.</span><span class="n">vocab</span><span class="o">.</span><span class="n">vocab</span><span class="p">(</span><span class="n">counter</span><span class="p">,</span> <span class="n">min_freq</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-70'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-70'>#</a>
            </div>
            <p>පුහුණුදත්ත පැටවුම සාදන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">287</span>    <span class="n">train_loader</span> <span class="o">=</span> <span class="n">DataLoader</span><span class="p">(</span><span class="n">train</span><span class="p">,</span> <span class="n">batch_size</span><span class="o">=</span><span class="n">c</span><span class="o">.</span><span class="n">batch_size</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="lineno">288</span>                              <span class="n">collate_fn</span><span class="o">=</span><span class="n">CollateFunc</span><span class="p">(</span><span class="n">tokenizer</span><span class="p">,</span> <span class="n">vocab</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">seq_len</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">vocab</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="n">vocab</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-71'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-71'>#</a>
            </div>
            <p>වලංගුදත්ත පැටවුම සාදන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">290</span>    <span class="n">valid_loader</span> <span class="o">=</span> <span class="n">DataLoader</span><span class="p">(</span><span class="n">valid</span><span class="p">,</span> <span class="n">batch_size</span><span class="o">=</span><span class="n">c</span><span class="o">.</span><span class="n">batch_size</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="lineno">291</span>                              <span class="n">collate_fn</span><span class="o">=</span><span class="n">CollateFunc</span><span class="p">(</span><span class="n">tokenizer</span><span class="p">,</span> <span class="n">vocab</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">seq_len</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">vocab</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="n">vocab</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-72'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-72'>#</a>
            </div>
            <p>ආපසු <code  class="highlight"><span></span><span class="n">n_classes</span></code>
<code  class="highlight"><span></span><span class="n">vocab</span></code>
, <code  class="highlight"><span></span><span class="n">train_loader</span></code>
, සහ <code  class="highlight"><span></span><span class="n">valid_loader</span></code>
 </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">294</span>    <span class="k">return</span> <span class="mi">4</span><span class="p">,</span> <span class="n">vocab</span><span class="p">,</span> <span class="n">train_loader</span><span class="p">,</span> <span class="n">valid_loader</span></pre></div>
        </div>
    </div>
    <div class='footer'>
        <a href="https://papers.labml.ai">Trending Research Papers</a>
        <a href="https://labml.ai">labml.ai</a>
    </div>
</div>
<script src=../interactive.js?v=1"></script>
<script>
    function handleImages() {
        var images = document.querySelectorAll('p>img')

        for (var i = 0; i < images.length; ++i) {
            handleImage(images[i])
        }
    }

    function handleImage(img) {
        img.parentElement.style.textAlign = 'center'

        var modal = document.createElement('div')
        modal.id = 'modal'

        var modalContent = document.createElement('div')
        modal.appendChild(modalContent)

        var modalImage = document.createElement('img')
        modalContent.appendChild(modalImage)

        var span = document.createElement('span')
        span.classList.add('close')
        span.textContent = 'x'
        modal.appendChild(span)

        img.onclick = function () {
            console.log('clicked')
            document.body.appendChild(modal)
            modalImage.src = img.src
        }

        span.onclick = function () {
            document.body.removeChild(modal)
        }
    }

    handleImages()
</script>
</body>
</html>